import java.net.*;
import java.io.*;
import org.apache.commons.net.ftp.FTPReply;;

public class Server extends Thread
{
	static GUI gui;
	static ServerSocket soc;
	static transferfile t;
	static boolean run;
	public Server(GUI g) throws IOException
	{
		gui=g;
		soc=new ServerSocket(5217);
		InetAddress ip  = InetAddress.getLocalHost();  
		gui.lblIPL.setText(ip.getHostAddress());
		gui.txtresults.append("FTP Server Started on Port Number 5217\n");
		run=true;
		start();
	}

	public void run(){
		do
		{
			gui.txtresults.append("Waiting for Connection ...\n");
			try {
				t=new transferfile(soc.accept(), gui);
			} catch (Exception e){
				e.printStackTrace();
				return;
			} 
			run = false;
		}while (run);
	}

	public static void quit() throws IOException{
		if (t!=null) {t.quit();}
		run=false;
		soc.close();
	}
}